package com.sjgtw.cloud.web.cuttingSlopeProtection.service.impl;

import com.sjgtw.cloud.common.core.constant.CacheConstants;
import com.sjgtw.cloud.common.core.utils.DateUtils;
import com.sjgtw.cloud.common.core.utils.SecurityUtils;
import com.sjgtw.cloud.common.redis.service.RedisService;
import com.sjgtw.cloud.system.api.model.LoginUser;
import com.sjgtw.cloud.web.cuttingSlopeProtection.domain.CuttingSlopeProtection;
import com.sjgtw.cloud.web.cuttingSlopeProtection.mapper.CuttingSlopeProtectionMapper;
import com.sjgtw.cloud.web.cuttingSlopeProtection.service.ICuttingSlopeProtectionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 路堑护坡Service业务层处理
 * 
 * @author lvyoufang
 * @date 2024-03-14
 */
@Service
public class CuttingSlopeProtectionServiceImpl implements ICuttingSlopeProtectionService 
{
    @Autowired
    private CuttingSlopeProtectionMapper cuttingSlopeProtectionMapper;

    @Autowired
    private RedisService redisService;

    /**
     * 查询路堑护坡
     * 
     * @param id 路堑护坡主键
     * @return 路堑护坡
     */
    @Override
    public CuttingSlopeProtection selectCuttingSlopeProtectionById(Long id)
    {
        return cuttingSlopeProtectionMapper.selectCuttingSlopeProtectionById(id);
    }

    /**
     * 查询路堑护坡列表
     * 
     * @param cuttingSlopeProtection 路堑护坡
     * @return 路堑护坡
     */
    @Override
    public List<CuttingSlopeProtection> selectCuttingSlopeProtectionList(CuttingSlopeProtection cuttingSlopeProtection)
    {
        return cuttingSlopeProtectionMapper.selectCuttingSlopeProtectionList(cuttingSlopeProtection);
    }

    /**
     * 新增路堑护坡
     * 
     * @param cuttingSlopeProtection 路堑护坡
     * @return 结果
     */
    @Override
    public int insertCuttingSlopeProtection(CuttingSlopeProtection cuttingSlopeProtection)
    {
        String token = SecurityUtils.getToken();
        String userKey = CacheConstants.LOGIN_TOKEN_KEY + token;
        LoginUser user = redisService.getCacheObject(userKey);
        Long userId = user.getUserid();
        String username = user.getUsername();

        cuttingSlopeProtection.setCreateUserId(userId);
        cuttingSlopeProtection.setCreateBy(username);
        cuttingSlopeProtection.setCreateTime(DateUtils.getNowDate());
        return cuttingSlopeProtectionMapper.insertCuttingSlopeProtection(cuttingSlopeProtection);
    }

    /**
     * 修改路堑护坡
     * 
     * @param cuttingSlopeProtection 路堑护坡
     * @return 结果
     */
    @Override
    public int updateCuttingSlopeProtection(CuttingSlopeProtection cuttingSlopeProtection)
    {
        String token = SecurityUtils.getToken();
        String userKey = CacheConstants.LOGIN_TOKEN_KEY + token;
        LoginUser user = redisService.getCacheObject(userKey);

        cuttingSlopeProtection.setUpdateBy(user.getUsername());
        cuttingSlopeProtection.setUpdateTime(DateUtils.getNowDate());
        return cuttingSlopeProtectionMapper.updateCuttingSlopeProtection(cuttingSlopeProtection);
    }

    /**
     * 批量删除路堑护坡
     * 
     * @param ids 需要删除的路堑护坡主键
     * @return 结果
     */
    @Override
    public int deleteCuttingSlopeProtectionByIds(String[] ids)
    {
        return cuttingSlopeProtectionMapper.deleteCuttingSlopeProtectionByIds(ids);
    }

    /**
     * 删除路堑护坡信息
     * 
     * @param id 路堑护坡主键
     * @return 结果
     */
    @Override
    public int deleteCuttingSlopeProtectionById(Long id)
    {
        return cuttingSlopeProtectionMapper.deleteCuttingSlopeProtectionById(id);
    }
}
